package com.gitee.sparta.pressure;

import com.gitee.sparta.api.SpartaTemplate;
import com.gitee.sparta.pressure.entity.PressureTest1Entity;
import com.gitee.sparta.pressure.entity.PressureTest2Entity;
import com.gitee.sparta.pressure.entity.PressureTest3Entity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Random;

/**
 * <p>
 *
 * </p>
 *
 * @author zyred
 * @since v 0.0.1
 */
//@RestController
@RequestMapping("/pressure")
public class PressureTestProvider {

    private Random random = new Random();
    private Random random2 = new Random();
    private Random random3 = new Random();
    @Autowired private SpartaTemplate<Object> spartaTemplate;


    @GetMapping("/begin")
    public void beginPressure (String username, String password, int num) {

        for (int i = 0; i < num; i++) {
            int ran = random.nextInt(100000);
            username += ran;
            password += ran;

            int anInt = random2.nextInt(1000000000);
            Long userId = Long.valueOf(String.valueOf(ran) + anInt);

            PressureTest1Entity pressureTest1Entity = new PressureTest1Entity(username, password, userId, LocalDateTime.now());
            PressureTest2Entity pressureTest2Entity = new PressureTest2Entity(username, password, userId, LocalDateTime.now());
            PressureTest3Entity pressureTest3Entity = new PressureTest3Entity(username, password, userId, LocalDateTime.now());
            PressureTest3Entity pressureTest4Entity = new PressureTest3Entity(username, password, userId, LocalDateTime.now());

            int expire = random3.nextInt(10000);
            spartaTemplate.write(PressureTestConstants.PRESSURE_TEST_1, pressureTest1Entity, expire);
            expire = random3.nextInt(10000);
            spartaTemplate.write(PressureTestConstants.PRESSURE_TEST_2, pressureTest2Entity, expire);
            expire = random3.nextInt(10000);
            spartaTemplate.write(PressureTestConstants.PRESSURE_TEST_3, pressureTest3Entity, expire);
            expire = random3.nextInt(10000);
            spartaTemplate.write(PressureTestConstants.PRESSURE_TEST_3, pressureTest4Entity, expire);
        }
    }
}
